<?php
class Submenu extends Controller
{

    function Submenu(){

        parent::Controller();

    }

   /* function extras($page = FALSE){

        $items['glossary'] = array('name' => 'Glossary', 'controller' => 'glossary');    
        $items['faq'] = array('name' => 'Faq', 'controller' => 'faq');    
        $items['articles'] = array('name' => 'Articles', 'controller' => 'articles');    
        $items['exhibitions'] = array('name' => 'Exhibitions', 'controller' => 'exhibitions');    
        $items['career_opportunities'] = array('name' => 'Career Opportunities', 'controller' => 'career_opportunities');  
        $items['friends'] = array('name' => 'Friends', 'controller' => 'friends');    

        switch ($page)
        {
            case 'glossary':
                $items['glossary']['selected'] = TRUE;  
            break;
            case 'faq':
                $items['faq']['selected'] = TRUE;  
            break;
            case 'articles':
                $items['articles']['selected'] = TRUE;  
            break;
            case 'exhibitions':
                $items['exhibitions']['selected'] = TRUE;  
            break;                     
            case 'career_opportunities':
                $items['career_opportunities']['selected'] = TRUE;  
            break;
            case 'friends':
                $items['friends']['selected'] = TRUE;  
            break;

        }
        
        $data['items'] = $items;
        $this->load->view("submenu", $data);       

    }   */

    public function portfolio($id = FALSE){

        $this->load->model('portfoliomodel');   

        if (!$id)                              
            $data['items'] = $this->portfoliomodel->get_submenu();
        else
            $data['items'] = $this->portfoliomodel->get_submenu_by_id($id);
        
        $this->load->view("submenu", $data);       
    }    

    public function news($ref = FALSE, $id = FALSE){

        $this->load->model('newsmodel');   
                              
        if (!$id)
            $data['items'] = $this->newsmodel->get_submenu_months();
        else {
            switch ($ref) {
                case "month":
                    $data['items'] = $this->newsmodel->get_submenu_by_month($id);
                    break;
                case "id":
                    $data['items'] = $this->newsmodel->get_submenu_by_id($id);
                    break;
            }
        }
        
        $this->load->view("submenu", $data);       
    }    

    public function publicity($ref = FALSE, $id = FALSE){

        $this->load->model('publicitymodel');   
                              
        if (!$id)
            $data['items'] = $this->publicitymodel->get_submenu_months();
        else {
            switch ($ref) {
                case "month":
                    $data['items'] = $this->publicitymodel->get_submenu_by_month($id);
                    break;
                case "id":
                    $data['items'] = $this->publicitymodel->get_submenu_by_id($id);
                    break;
            }
        }
        
        $this->load->view("submenu", $data);       
    }

    // returns submenu for Extras. If $array and $selected are received, $array is inserted as content of $selected.
    private function add_extras($selected = '', $array = array()){

        $items['glossary'] = array('name' => 'Glossary', 'controller' => 'glossary');    
        $items['faq'] = array('name' => 'Faq', 'controller' => 'faq');    
        $items['articles'] = array('name' => 'Articles', 'controller' => 'articles');    
        $items['exhibitions'] = array('name' => 'Exhibitions', 'controller' => 'exhibitions');    
        $items['career_opportunities'] = array('name' => 'Career Opportunities', 'controller' => 'career_opportunities');  
        $items['friends'] = array('name' => 'Friends', 'controller' => 'friends');    

        switch ($selected)
        {
            case 'glossary':
                $items['glossary']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['glossary']['content'] = $array;
            break;
            case 'faq':
                $items['faq']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['faq']['content'] = $array;
            break;
            case 'articles':
                $items['articles']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['articles']['content'] = $array;
            break;
            case 'exhibitions':
                $items['exhibitions']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['exhibitions']['content'] = $array;
            break;                     
            case 'career_opportunities':
                $items['career_opportunities']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['glossary']['content'] = $array;
            break;
            case 'friends':
                $items['friends']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['friends']['content'] = $array;
            break;

        }

        return $items;

    }

    public function extras(){

        $data['items'] = $this->add_extras();
        $this->load->view("submenu", $data);      

    }                 

    public function glossary($ref = FALSE, $id = FALSE){

        $this->load->model('glossarymodel');

        if (!$id)
            $items = $this->glossarymodel->get_submenu();
        else {
            switch ($ref) {
                case "letter":
                    $items = $this->glossarymodel->get_submenu_by_letter($id);
                    break;
                case "id":
                    $items = $this->glossarymodel->get_submenu_by_id($id);
                    break;
            }
        }

        $data['items'] = $this->add_extras('glossary', $items);
        $this->load->view("submenu", $data);  

    }                 
  
    public function faq(){

        $data['items'] = $this->add_extras('faq');
        $this->load->view("submenu", $data);      

    }

    public function articles($ref = FALSE, $id = FALSE){

        $this->load->model('articlesmodel');   
                              
        if (!$id)
            $items = $this->articlesmodel->get_submenu_months();
        else {
            switch ($ref) {
                case "month":
                    $items = $this->articlesmodel->get_submenu_by_month($id);
                    break;
                case "id":
                    $items = $this->articlesmodel->get_submenu_by_id($id);
                    break;
            }
        }

        $data['items'] = $this->add_extras('articles', $items);
        $this->load->view("submenu", $data);       
    }          

    public function exhibitions($ref = FALSE, $id = FALSE){

        $this->load->model('exhibitionsmodel');   
                              
        if (!$id)
            $items = $this->exhibitionsmodel->get_submenu_months();
        else {
            switch ($ref) {
                case "month":
                    $items = $this->exhibitionsmodel->get_submenu_by_month($id);
                    break;
                case "id":
                    $items = $this->exhibitionsmodel->get_submenu_by_id($id);
                    break;
            }
        }
        
        $data['items'] = $this->add_extras('exhibitions', $items);
        $this->load->view("submenu", $data);       
    }
                                                                
    public function career_opportunities(){

        $data['items'] = $this->add_extras('career_opportunities');
        $this->load->view("submenu", $data);      

    }

    public function friends($id = FALSE){

        $items = $this->friendsmodel->get_submenu_list($id);
        $data['items'] = $this->add_extras('friends', $items);        

        $this->load->view("submenu", $data);      

    }

    // returns submenu for Insider. If $array and $selected are received, $array is inserted as content of $selected.
    private function add_insider($selected = '', $array = array()){

        if (!session_check()) {
         			
			$items['login'] = array('name' => 'Login', 'controller' => 'login');    
			$items['register'] = array('name' => 'Create an Account', 'controller' => 'register');    
			$items['newsletters'] = array('name' => 'Newsletters', 'controller' => 'newsletters');    
	
			switch ($selected)
			{
				case 'login':
					$items['login']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['login']['content'] = $array;
				break;
				case 'register':
					$items['register']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['register']['content'] = $array;
				break;
				case 'newsletters':
					$items['newsletters']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['newsletters']['content'] = $array;
				break;
			}
			
		} else {

			$items['profile'] = array('name' => 'Your Profile', 'controller' => 'insider/profile');    
			$items['edit_password'] = array('name' => 'Change Password', 'controller' => 'insider/edit_password');
			$items['logout'] = array('name' => 'Logout', 'controller' => 'logout');    
	
			switch ($selected)
			{
				case 'profile':
					$items['profile']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['profile']['content'] = $array;
				break;
				case 'edit_password':
					$items['edit_password']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['edit_password']['content'] = $array;
				break;
				case 'logout':
					$items['logout']['selected'] = TRUE;  
					if (sizeof($array > 0)) $items['logout']['content'] = $array;
				break;
			}

			
		}

        return $items;

    }

    public function insider(){

        $data['items'] = $this->add_insider();
        $this->load->view("submenu", $data);      

    }                 

    public function login(){

        $data['items'] = $this->add_insider('login');
        $this->load->view("submenu", $data);      

    }                 
                                                    
    public function register(){

        $data['items'] = $this->add_insider('register');
        $this->load->view("submenu", $data);      

    }                 

    public function newsletters(){

        $data['items'] = $this->add_insider('newsletters');
        $this->load->view("submenu", $data);      

    }     

    public function profile(){

        $data['items'] = $this->add_insider('profile');
        $this->load->view("submenu", $data);      

    }      

    public function edit_password(){

        $data['items'] = $this->add_insider('edit_password');
        $this->load->view("submenu", $data);      

    }      

    /*
    public function search($results = array()){

        $data['items'] = array();
                                         
        foreach ($results as $result) {

            if (!empty($result['items'])) {

                $data['items'][] = array(
                                        'display' => $result['name'].' ('.count($result['items']).')',
                                        'controller' => $result['name'],
                                    );
            }               
        }

        $this->load->view("search_filter", $data);      

    } 
    */                

    // returns submenu for Products. If $array and $selected are received, $array is inserted as content of $selected.
    private function add_products($selected = '', $array = array()){

        $items['by_category'] = array('name' => 'Products by Category', 'controller' => 'products/categories');    
        $items['by_application'] = array('name' => 'Products by Application', 'controller' => 'products/applications');    
        $items['one_off'] = array('name' => 'One-off Floors', 'controller' => 'products/one_off_floors');     

        switch ($selected)
        {
            case 'by_category':
                $items['by_category']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['by_category']['content'] = $array;
            break;
            case 'by_application':
                $items['by_application']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['by_application']['content'] = $array;
            break;
            case 'one_off':
                $items['one_off']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['one_off']['content'] = $array;
            break; 

        }

        return $items;

    }

    public function products(){

        $data['items'] = $this->add_products();
        $this->load->view("submenu", $data);      

    }

    public function products_by_category($id = FALSE, $prod_id = FALSE){

        $this->load->model('productsmodel');   
                              
        $items = $this->productsmodel->get_submenu_categories($id, $prod_id);

        $data['items'] = $this->add_products('by_category', $items);

        $this->load->view("submenu", $data);  

    }

    public function products_by_subcategory($id = FALSE, $prod_id = FALSE){

        $this->load->model('productsmodel');   
                              
        $items = $this->productsmodel->get_submenu_subcategories($id, $prod_id);

        $data['items'] = $this->add_products('by_category', $items);

        $this->load->view("submenu", $data);  

    }

    public function products_by_application($id = FALSE){

        $this->load->model('productsmodel');   
                              
        $items = $this->productsmodel->get_submenu_applications($id);

        $data['items'] = $this->add_products('by_application', $items); 

        $this->load->view("submenu", $data);  

    }  

    public function products_one_off($id = FALSE){

        $this->load->model('productsmodel');   
                              
        $items = $this->productsmodel->get_submenu_one_off($id);

        $data['items'] = $this->add_products('one_off', $items);

        $this->load->view("submenu", $data);  

    }  

    // returns submenu for Wishlist. $selected is the current wishlist. $array is the array of wishlists.
    private function add_wishlist($selected = FALSE, $array = array()){

        $items[] = array('name' => 'View All', 'controller' => 'wishlist');    
        if ($selected == FALSE) $items[0]['selected'] = TRUE;  

        foreach ($array as $row){

            if ($selected == $row['param']) $row['selected'] = TRUE;  

            $items[] = $row;

        }

        /*
        switch ($selected)
        {
            case 'login':
                $items['login']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['login']['content'] = $array;
            break;
            case 'register':
                $items['register']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['register']['content'] = $array;
            break;
            case 'newsletters':
                $items['newsletters']['selected'] = TRUE;  
                if (sizeof($array > 0)) $items['newsletters']['content'] = $array;
            break;
        }
        */

        return $items;

    }

    public function wishlist($id = FALSE){

        $this->load->model('wishlistsmodel');   
                              
        $items = $this->wishlistsmodel->get_submenu_wishlists($this->session->userdata('user_id'));

        $data['items'] = $this->add_wishlist($id, $items);

        $this->load->view("submenu", $data);  
        

    }  
  
}
?>
